package gsw.tool.eventbus.response;

import android.util.Log;

import com.google.gson.Gson;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import gsw.tool.eventbus.request.RequestBean;
import gsw.tool.eventbus.util.TypeUtils;

/**
 * 生成单例对象的ResponceMake，单例对象必须包含getInstance方法
 */
public class InstanceResponceMake extends ResponceMake {
    private Method mMethod;

    @Override
    protected void setMethod(RequestBean requestBean) {
        String methodName = requestBean.getMethodName();
        //getInstance方法
        mMethod = TypeUtils.getMethodForGettingInstance(reslutClass, methodName, parameterTypes);
    }

    @Override
    protected Object invokeMethod() {
        Object object = null;
        try {
            object = mMethod.invoke(null, mParameters);
            OBJECT_CENTER.putObject(object.getClass().getName(), object);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        return null;
    }
}
